<?php
/*
 *  FireFly theme
 *  (c) 2011, chugylo
 */

function get_theme_settings() {
    // parse ini-file for user settings
    $firefly_settings = parse_ini_file(get_template_directory() .'/firefly.ini');
    return $firefly_settings;
}

function most_commented_list($num=5) {
    // print list of most commented posts
    global $wpdb;
    $sql =
        // FIXME: is realy Wordpress generates URL from post_date or maybe from post_date_gmt etc?
        "SELECT post_date, post_title, post_name, comment_count
        FROM $wpdb->posts
        ORDER BY comment_count DESC
        LIMIT $num";
    $result = $wpdb->get_results($sql);
    $array = array();
    foreach ($result as $r) {
        $date = explode(' ', $r->post_date);
        $date = $date[0];
        $year = substr($date, 0, 4);
        $month = substr($date, 5, 2);
        $day = substr($date, 8, 2);
        $url = site_url() ."/$year/$month/$day/$r->post_name/";
        $array[] = array($r->post_title, $url, $r->comment_count);
    }
    foreach ($array as $a)
        // $a[0] - title
        // $a[1] - URL
        // $a[2] - comment count
        echo "    <li><a href=\"$a[1]\">$a[0]</a></li>\n";
}

function copyright_years() {
    // Print years for copyright notice. It gets foundation year from
    // theme settings and minds about current year.
    $current_year = date('Y');
    $settings = get_theme_settings();
    if ($current_year == $settings['foundation_year'])
        echo $current_year;
    else
        echo "${settings['foundation_year']}–$current_year";
}

function copyright_name() {
    // print copyright name
    $settings = get_theme_settings();
    echo $settings['copyright_name'];
}

function firefly_version() {
    // print FireFly version (letter "v" and numbers)
    $settings = get_theme_settings();
    echo 'v'. $settings['firefly_version'];
}

?>